package org.cloudplatform.common.feign.zk;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.cloudplatform.common.feign.register.InstanceRegister;

import java.util.List;

/**
 * 类描述：
 * 作者：徐卫超 (cc)
 * 时间 2022/5/17 9:43
 */
@Slf4j
public class ServiceSyncCache implements Runnable {


    private String path;
    private String serviceName;
    private CuratorFramework curatorFramework;
    private InstanceRegister register;


    public ServiceSyncCache(String path, String serviceName, CuratorFramework curatorFramework,
                                InstanceRegister register) {
        this.path = path;
        this.curatorFramework = curatorFramework;
        this.serviceName = serviceName;
        this.register = register;
    }


    @Override
    public void run() {
        try {
            doRun();
        } catch (Exception e) {
            log.error("数据同步错误：{}", path, e);
        }
    }

    public void doRun() throws Exception {
        List<String> serviceIds = curatorFramework.getChildren().forPath(path);
        for (String serviceId : serviceIds) {
            log.info("服务信息：{}", serviceId);
        }
    }
}
